package com.example.streamer.api;

import com.example.streamer.util.WindowUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
@RequestMapping("/api/windows")
public class WindowController {
    private static volatile String currentHwnd = null;

    @GetMapping("/list")
    public List<HashMap<String, String>> listWindows() {
        return WindowUtils.listWindows().stream().map(w -> {
            HashMap<String, String> map = new HashMap<>();
            map.put("hwnd", w.hwnd.getPointer().toString());
            map.put("title", w.title);
            return map;
        }).collect(Collectors.toList());
    }

    @PostMapping("/set")
    public String setWindow(@RequestParam("hwnd") String hwnd) {
        currentHwnd = hwnd;
        return "ok";
    }

    public static String getCurrentHwnd() {
        return currentHwnd;
    }
} 